home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / ColorPicker.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  11.8 KB  |  441 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        ColorPicker.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __COLORPICKER__
  18. #define __COLORPICKER__
  19.  
  20.  
  21. #ifndef __QUICKDRAW__
  22. #include <Quickdraw.h>
  23. #endif
  24. /*    #include <Types.h>                                            */
  25. /*        #include <ConditionalMacros.h>                            */
  26. /*    #include <MixedMode.h>                                        */
  27. /*    #include <QuickdrawText.h>                                    */
  28.  
  29. #ifndef __WINDOWS__
  30. #include <Windows.h>
  31. #endif
  32. /*    #include <Memory.h>                                            */
  33. /*    #include <Events.h>                                            */
  34. /*        #include <OSUtils.h>                                    */
  35. /*    #include <Controls.h>                                        */
  36. /*        #include <Menus.h>                                        */
  37.  
  38. #ifndef __DIALOGS__
  39. #include <Dialogs.h>
  40. #endif
  41. /*    #include <Errors.h>                                            */
  42. /*    #include <TextEdit.h>                                        */
  43.  
  44. #ifndef __CMAPPLICATION__
  45. #include <CMApplication.h>
  46. #endif
  47. /*    #include <Printing.h>                                        */
  48.  
  49. #ifndef __BALLOONS__
  50. #include <Balloons.h>
  51. #endif
  52.  
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56.  
  57. #if GENERATINGPOWERPC
  58. #pragma options align=mac68k
  59. #endif
  60.  
  61. #ifdef __CFM68K__
  62. #pragma lib_export on
  63. #endif
  64.  
  65.  
  66. enum {
  67. /*Maximum small fract value, as long*/
  68.     MaxSmallFract                = 0x0000FFFF
  69. };
  70.  
  71. enum {
  72.     kDefaultWidth                = 383,
  73.     kDefaultHeight                = 238
  74. };
  75.  
  76. enum PickerActions {
  77.     kDidNothing,
  78.     kColorChanged,
  79.     kOkHit,
  80.     kCancelHit,
  81.     kNewPickerChosen,
  82.     kApplItemHit
  83. };
  84.  
  85. typedef short PickerAction;
  86.  
  87.  
  88. enum ColorTypes {
  89.     kOriginalColor,
  90.     kNewColor
  91. };
  92.  
  93. typedef short ColorType;
  94.  
  95.  
  96. enum EditOperations {
  97.     kCut,
  98.     kCopy,
  99.     kPaste,
  100.     kClear,
  101.     kUndo
  102. };
  103.  
  104. typedef short EditOperation;
  105.  
  106.  
  107. enum ItemHitModifiers {
  108.     kMouseDown,
  109.     kKeyDown,
  110.     kFieldEntered,
  111.     kFieldLeft,
  112.     kCutOp,
  113.     kCopyOp,
  114.     kPasteOp,
  115.     kClearOp,
  116.     kUndoOp
  117. };
  118.  
  119. typedef short ItemModifier;
  120.  
  121.  
  122. enum DialogPlacementSpecifiers {
  123.     kAtSpecifiedOrigin,
  124.     kDeepestColorScreen,
  125.     kCenterOnMainScreen
  126. };
  127.  
  128. typedef short DialogPlacementSpec;
  129.  
  130.  
  131. enum {
  132.     DialogIsMoveable            = 1,
  133.     DialogIsModal                = 2,
  134.     CanModifyPalette            = 4,
  135.     CanAnimatePalette            = 8,
  136.     AppIsColorSyncAware            = 16,
  137.     InSystemDialog                = 32,
  138.     InApplicationDialog            = 64,
  139.     InPickerDialog                = 128,
  140.     DetachedFromChoices            = 256,
  141.     CanDoColor                    = 1,
  142.     CanDoBlackWhite                = 2,
  143.     AlwaysModifiesPalette        = 4,
  144.     MayModifyPalette            = 8,
  145.     PickerIsColorSyncAware        = 16,
  146.     CanDoSystemDialog            = 32,
  147.     CanDoApplDialog                = 64,
  148.     HasOwnDialog                = 128,
  149.     CanDetach                    = 256
  150. };
  151.  
  152. enum EventForcasters {
  153.     kNoForcast,
  154.     kMenuChoice,
  155.     kDialogAccept,
  156.     kDialogCancel,
  157.     kLeaveFocus,
  158.     kPickerSwitch,
  159.     kNormalKeyDown,
  160.     kNormalMouseDown
  161. };
  162.  
  163. typedef short EventForcaster;
  164.  
  165. /* A SmallFract value is just the fractional part of a Fixed number,
  166. which is the low order word.  SmallFracts are used to save room,
  167. and to be compatible with Quickdraw's RGBColor.  They can be
  168. assigned directly to and from INTEGERs. */
  169. /* Unsigned fraction between 0 and 1 */
  170. typedef unsigned short SmallFract;
  171.  
  172. /* For developmental simplicity in switching between the HLS and HSV
  173. models, HLS is reordered into HSL. Thus both models start with
  174. hue and saturation values; value/lightness/brightness is last. */
  175. struct HSVColor {
  176.     SmallFract                        hue;                        /*Fraction of circle, red at 0*/
  177.     SmallFract                        saturation;                    /*0-1, 0 for gray, 1 for pure color*/
  178.     SmallFract                        value;                        /*0-1, 0 for black, 1 for max intensity*/
  179. };
  180. typedef struct HSVColor HSVColor;
  181.  
  182. struct HSLColor {
  183.     SmallFract                        hue;                        /*Fraction of circle, red at 0*/
  184.     SmallFract                        saturation;                    /*0-1, 0 for gray, 1 for pure color*/
  185.     SmallFract                        lightness;                    /*0-1, 0 for black, 1 for white*/
  186. };
  187. typedef struct HSLColor HSLColor;
  188.  
  189. struct CMYColor {
  190.     SmallFract                        cyan;
  191.     SmallFract                        magenta;
  192.     SmallFract                        yellow;
  193. };
  194. typedef struct CMYColor CMYColor;
  195.  
  196. struct PMColor {
  197.     CMProfileHandle                    profile;
  198.     CMColor                            color;
  199. };
  200. typedef struct PMColor PMColor, *PMColorPtr;
  201.  
  202. typedef struct PrivatePickerRecord **picker;
  203.  
  204. struct PickerIconData {
  205.     short                            scriptCode;
  206.     short                            iconSuiteID;
  207.     ResType                            helpResType;
  208.     short                            helpResID;
  209. };
  210. typedef struct PickerIconData PickerIconData;
  211.  
  212. struct PickerInitData {
  213.     DialogPtr                        pickerDialog;
  214.     DialogPtr                        choicesDialog;
  215.     long                            flags;
  216.     picker                            yourself;
  217. };
  218. typedef struct PickerInitData PickerInitData;
  219.  
  220. /* This is the same structure as GX's gxEditMenuRecord.  Maybe use that?*/
  221. struct MenuItemInfo {
  222.     short                            editMenuID;
  223.     short                            cutItem;
  224.     short                            copyItem;
  225.     short                            pasteItem;
  226.     short                            clearItem;
  227.     short                            undoItem;
  228. };
  229. typedef struct MenuItemInfo MenuItemInfo;
  230.  
  231. struct MenuState {
  232.     Boolean                            cutEnabled;
  233.     Boolean                            copyEnabled;
  234.     Boolean                            pasteEnabled;
  235.     Boolean                            clearEnabled;
  236.     Boolean                            undoEnabled;
  237.     Str255                            undoString;
  238. };
  239. typedef struct MenuState MenuState;
  240.  
  241. typedef pascal void (*ColorChangedProcPtr)(long userData, struct PMColor *newColor);
  242. typedef pascal Boolean (*UserEventProcPtr)(EventRecord *event);
  243.  
  244. #if GENERATINGCFM
  245. typedef UniversalProcPtr ColorChangedUPP;
  246. typedef UniversalProcPtr UserEventUPP;
  247. #else
  248. typedef ColorChangedProcPtr ColorChangedUPP;
  249. typedef UserEventProcPtr UserEventUPP;
  250. #endif
  251.  
  252. struct ColorPickerInfo {
  253.     struct PMColor                    theColor;
  254.     CMProfileHandle                    dstProfile;
  255.     long                            flags;
  256.     DialogPlacementSpec                placeWhere;
  257.     Point                            dialogOrigin;
  258.     long                            pickerType;
  259.     UserEventUPP                    eventProc;
  260.     ColorChangedUPP                    colorProc;
  261.     long                            colorProcData;
  262.     Str255                            prompt;
  263.     struct MenuItemInfo                mInfo;
  264.     Boolean                            newColorChosen;
  265.     SInt8                            filler;
  266. };
  267. typedef struct ColorPickerInfo ColorPickerInfo;
  268.  
  269. struct SystemDialogInfo {
  270.     long                            flags;
  271.     long                            pickerType;
  272.     DialogPlacementSpec                placeWhere;
  273.     Point                            dialogOrigin;
  274.     struct MenuItemInfo                mInfo;
  275. };
  276. typedef struct SystemDialogInfo SystemDialogInfo;
  277.  
  278. struct PickerDialogInfo {
  279.     long                            flags;
  280.     long                            pickerType;
  281.     Point                            *dialogOrigin;
  282.     struct MenuItemInfo                mInfo;
  283. };
  284. typedef struct PickerDialogInfo PickerDialogInfo;
  285.  
  286. struct ApplicationDialogInfo {
  287.     long                            flags;
  288.     long                            pickerType;
  289.     DialogPtr                        theDialog;
  290.     Point                            pickerOrigin;
  291.     struct MenuItemInfo                mInfo;
  292. };
  293. typedef struct ApplicationDialogInfo ApplicationDialogInfo;
  294.  
  295. struct EventData {
  296.     EventRecord                        *event;
  297.     PickerAction                    action;
  298.     short                            itemHit;
  299.     Boolean                            handled;
  300.     SInt8                            filler;
  301.     ColorChangedUPP                    colorProc;
  302.     long                            colorProcData;
  303.     EventForcaster                    forcast;
  304. };
  305. typedef struct EventData EventData;
  306.  
  307. struct EditData {
  308.     EditOperation                    theEdit;
  309.     PickerAction                    action;
  310.     Boolean                            handled;
  311.     SInt8                            filler;
  312. };
  313. typedef struct EditData EditData;
  314.  
  315. struct ItemHitData {
  316.     short                            itemHit;
  317.     ItemModifier                    iMod;
  318.     PickerAction                    action;
  319.     ColorChangedUPP                    colorProc;
  320.     long                            colorProcData;
  321.     Point                            where;
  322. };
  323. typedef struct ItemHitData ItemHitData;
  324.  
  325. struct HelpItemInfo {
  326.     long                            options;
  327.     Point                            tip;
  328.     Rect                            altRect;
  329.     short                            theProc;
  330.     short                            helpVariant;
  331.     HMMessageRecord                    helpMessage;
  332. };
  333. typedef struct HelpItemInfo HelpItemInfo;
  334.  
  335. /*    Below are the color conversion routines.*/
  336. extern pascal SmallFract Fix2SmallFract(Fixed f)
  337.  THREEWORDINLINE(0x3F3C, 0x0001, 0xA82E);
  338. extern pascal Fixed SmallFract2Fix(SmallFract s)
  339.  THREEWORDINLINE(0x3F3C, 0x0002, 0xA82E);
  340. extern pascal void CMY2RGB(const CMYColor *cColor, RGBColor *rColor)
  341.  THREEWORDINLINE(0x3F3C, 0x0003, 0xA82E);
  342. extern pascal void RGB2CMY(const RGBColor *rColor, CMYColor *cColor)
  343.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA82E);
  344. extern pascal void HSL2RGB(const HSLColor *hColor, RGBColor *rColor)
  345.  THREEWORDINLINE(0x3F3C, 0x0005, 0xA82E);
  346. extern pascal void RGB2HSL(const RGBColor *rColor, HSLColor *hColor)
  347.  THREEWORDINLINE(0x3F3C, 0x0006, 0xA82E);
  348. extern pascal void HSV2RGB(const HSVColor *hColor, RGBColor *rColor)
  349.  THREEWORDINLINE(0x3F3C, 0x0007, 0xA82E);
  350. extern pascal void RGB2HSV(const RGBColor *rColor, HSVColor *hColor)
  351.  THREEWORDINLINE(0x3F3C, 0x0008, 0xA82E);
  352. /*    Below brings up the ColorPicker 1.0 Dialog*/
  353. extern pascal Boolean GetColor(Point where, ConstStr255Param prompt, const RGBColor *inColor, RGBColor *outColor)
  354.  THREEWORDINLINE(0x3F3C, 0x0009, 0xA82E);
  355. /*    Below are the ColorPicker 2.0 routines.*/
  356. extern pascal OSErr PickColor(ColorPickerInfo *theColorInfo)
  357.  THREEWORDINLINE(0x3F3C, 0x0213, 0xA82E);
  358. extern pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info, picker *thePicker)
  359.  THREEWORDINLINE(0x3F3C, 0x0414, 0xA82E);
  360. extern pascal OSErr CreateColorDialog(SystemDialogInfo *info, picker *thePicker)
  361.  THREEWORDINLINE(0x3F3C, 0x0415, 0xA82E);
  362. extern pascal OSErr CreatePickerDialog(PickerDialogInfo *info, picker *thePicker)
  363.  THREEWORDINLINE(0x3F3C, 0x0416, 0xA82E);
  364. extern pascal OSErr DisposeColorPicker(picker thePicker)
  365.  THREEWORDINLINE(0x3F3C, 0x0217, 0xA82E);
  366. extern pascal OSErr GetPickerVisibility(picker thePicker, Boolean *visible)
  367.  THREEWORDINLINE(0x3F3C, 0x0418, 0xA82E);
  368. extern pascal OSErr SetPickerVisibility(picker thePicker, short visible)
  369.  THREEWORDINLINE(0x3F3C, 0x0319, 0xA82E);
  370. extern pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString)
  371.  THREEWORDINLINE(0x3F3C, 0x041a, 0xA82E);
  372. extern pascal OSErr DoPickerEvent(picker thePicker, EventData *data)
  373.  THREEWORDINLINE(0x3F3C, 0x041b, 0xA82E);
  374. extern pascal OSErr DoPickerEdit(picker thePicker, EditData *data)
  375.  THREEWORDINLINE(0x3F3C, 0x041c, 0xA82E);
  376. extern pascal OSErr DoPickerDraw(picker thePicker)
  377.  THREEWORDINLINE(0x3F3C, 0x021d, 0xA82E);
  378. extern pascal OSErr GetPickerColor(picker thePicker, ColorType whichColor, PMColor *color)
  379.  THREEWORDINLINE(0x3F3C, 0x051e, 0xA82E);
  380. extern pascal OSErr SetPickerColor(picker thePicker, ColorType whichColor, PMColor *color)
  381.  THREEWORDINLINE(0x3F3C, 0x051f, 0xA82E);
  382. extern pascal OSErr GetPickerOrigin(picker thePicker, Point *where)
  383.  THREEWORDINLINE(0x3F3C, 0x0420, 0xA82E);
  384. extern pascal OSErr SetPickerOrigin(picker thePicker, Point where)
  385.  THREEWORDINLINE(0x3F3C, 0x0421, 0xA82E);
  386. extern pascal OSErr GetPickerProfile(picker thePicker, CMProfileHandle *profile)
  387.  THREEWORDINLINE(0x3F3C, 0x0422, 0xA82E);
  388. extern pascal OSErr SetPickerProfile(picker thePicker, CMProfileHandle profile)
  389.  THREEWORDINLINE(0x3F3C, 0x0423, 0xA82E);
  390. extern pascal OSErr GetPickerEditMenuState(picker thePicker, MenuState *mState)
  391.  THREEWORDINLINE(0x3F3C, 0x0424, 0xA82E);
  392. extern pascal OSErr ExtractPickerHelpItem(picker thePicker, short itemNo, short whichState, HelpItemInfo *helpInfo)
  393.  THREEWORDINLINE(0x3F3C, 0x0625, 0xA82E);
  394. enum {
  395.     uppColorChangedProcInfo = kPascalStackBased
  396.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
  397.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct PMColor*))),
  398.     uppUserEventProcInfo = kPascalStackBased
  399.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  400.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(EventRecord*)))
  401. };
  402.  
  403. #if GENERATINGCFM
  404. #define NewColorChangedProc(userRoutine)        \
  405.         (ColorChangedUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppColorChangedProcInfo, GetCurrentArchitecture())
  406. #define NewUserEventProc(userRoutine)        \
  407.         (UserEventUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUserEventProcInfo, GetCurrentArchitecture())
  408. #else
  409. #define NewColorChangedProc(userRoutine)        \
  410.         ((ColorChangedUPP) (userRoutine))
  411. #define NewUserEventProc(userRoutine)        \
  412.         ((UserEventUPP) (userRoutine))
  413. #endif
  414.  
  415. #if GENERATINGCFM
  416. #define CallColorChangedProc(userRoutine, userData, newColor)        \
  417.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppColorChangedProcInfo, (userData), (newColor))
  418. #define CallUserEventProc(userRoutine, event)        \
  419.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppUserEventProcInfo, (event))
  420. #else
  421. #define CallColorChangedProc(userRoutine, userData, newColor)        \
  422.         (*(userRoutine))((userData), (newColor))
  423. #define CallUserEventProc(userRoutine, event)        \
  424.         (*(userRoutine))((event))
  425. #endif
  426.  
  427.  
  428. #ifdef __CFM68K__
  429. #pragma lib_export off
  430. #endif
  431.  
  432. #if GENERATINGPOWERPC
  433. #pragma options align=reset
  434. #endif
  435.  
  436. #ifdef __cplusplus
  437. }
  438. #endif
  439.  
  440. #endif /* __COLORPICKER__ */
  441.